package cn.fl.carloan.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.upload.condition.SysUlFilesRecQueryCondition;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.audit.service.IAudCreditInfoService;
import cn.fl.audit.service.IAudInterviewInfoService;
import cn.fl.audit.service.IAudReturnVisitService;
import cn.fl.audit.service.IAudStandingBookService;
import cn.fl.carloan.service.IOdrBscInfoService;
import cn.fl.carloan.vo.OdrBscInfoVO;
import cn.fl.carloan.vo.OdrPrdBscInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjPrdPaySchMService;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.vo.SysUlFilesRecVO;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import fl.carloan.facade.carloan.api.IOdrBscInfoApiService;
import fl.carloan.facade.carloan.api.IOdrPrdBscInfoApiService;
import fl.carloan.facade.carloan.condition.OdrBscInfoQC;
import fl.carloan.facade.carloan.constant.OdrBscInfoConstant;
import fl.carloan.facade.carloan.constant.OdrPrdBscInfoConstant;
import fl.carloan.facade.carloan.dto.OdrBscInfoDTO;
import fl.carloan.facade.carloan.utils.CalendarUtils;
import fl.flow.facade.flow.api.IFlowApiService;
import fl.flow.facade.flow.condition.SysFlowManageVQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.flow.facade.flow.dto.SysFlowManageVDTO;

/**
 * @Description: 预约记录表 控制层
 */
@Controller
@RequestMapping("/carloan/odrbscinfo")
public class OdrBscInfoController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(OdrBscInfoController.class);

	/**
	 * OdrBscInfo 服务层BEAN
	 */
	@Autowired
	private IOdrBscInfoService odrBscInfoService;
	
	@Autowired
	private IOdrBscInfoApiService odrBscInfoApiService;
	
	@Autowired
	private IFlowApiService flowApiService;
	
	@Autowired
	private IAudReturnVisitService audReturnVisitService;

	@Autowired
	private IAudCreditInfoService audCreditInfoService;
	
	@Autowired
	private IAudStandingBookService audStandingBookService;
	
	@Autowired
	private IAudInterviewInfoService audInterviewInfoService;
	
	@Autowired
	private IPrjPrdPaySchMService prjPrdPaySchMService;
	
	@Autowired
	private IOdrPrdBscInfoApiService odrPrdBscInfoApiService;
	
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	
	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toListPage", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		ModelAndView view = new ModelAndView("carloan/odrbscinfo/odrBscInfoList");
		// 事业部
		List<KeyValueVO> orgList = this.odrBscInfoService.searchBusinessOrgList();
		List<KeyValueVO> odrStsCdList =this.odrBscInfoService.getOdrStsCdList();
		view.addObject("orgList", orgList);
		view.addObject("odrStsCdList", odrStsCdList);
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toListPage", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", "加载例子详细页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("carloan/odrbscinfo/odrBscInfoDetail");
		view.addObject("id", id);
		OdrBscInfoVO vo = this.odrBscInfoService.selectById(Long.valueOf(id));
		view.addObject("odrBscInfo",vo);
		//查询数据字典配置
		Double lgjAmt = null;//留购价
		Double yearPct = null;//年利率
		List<String> grpCdList = new ArrayList<String>();
		grpCdList.add(DictionaryConstant.CODE__CDD_FEE_LIST);
		grpCdList.add(DictionaryConstant.CODE__PRJ_ODR_DEF_ANN);
		Map<String, List<KeyValueVO>> multiKvList = this.sysDictionaryApiService.getMultiKvList(grpCdList, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		if(!multiKvList.isEmpty()){
			List<KeyValueVO> lgjAmtList = multiKvList.get(DictionaryConstant.CODE__CDD_FEE_LIST);
			if(CollectionUtils.isNotEmpty(lgjAmtList)){
				KeyValueVO keyValueVO = lgjAmtList.get(0);
				if(StringUtils.isNotEmpty(keyValueVO.getValue())){
					lgjAmt = DecimalUtils.convertFenToYuan(Long.valueOf(keyValueVO.getValue()));
				}
			}
			List<KeyValueVO> yearPctList = multiKvList.get(DictionaryConstant.CODE__PRJ_ODR_DEF_ANN);
			if(CollectionUtils.isNotEmpty(yearPctList)){
				KeyValueVO keyValueVO = yearPctList.get(0);
				if(StringUtils.isNotEmpty(keyValueVO.getValue())){
					yearPct = Double.valueOf(keyValueVO.getValue());
				}
			}
		}
		view.addObject("lgjAmt", lgjAmt);
		view.addObject("yearPct", yearPct);
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", " 加载例子详细页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String odrNo = request.getParameter("odrNo");//预约编号
		String cstNm = request.getParameter("cstNm");//客户名称
		String cstMgrNm = request.getParameter("cstMgrNm");//客户经理
		String odrStsCd = request.getParameter("odrStsCd");//预约状态
		String firstUsrNm = request.getParameter("firstUsrNm");//一级推荐人名称
		String secondUsrNm = request.getParameter("secondUsrNm");//二级推荐人名称
		String buOrgCd = request.getParameter("buOrgCd");//所属事业部
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		OdrBscInfoQC qc = new OdrBscInfoQC();
		if (StringUtils.isNotEmpty(odrNo)) {
			qc.setOdrNo(odrNo);
		}
		if (StringUtils.isNotEmpty(cstNm)) {
			qc.setCstNm(cstNm);
		}
		if (StringUtils.isNotEmpty(cstMgrNm)) {
			qc.setCstMgrNm(cstMgrNm);
		}
		if (StringUtils.isNotEmpty(odrStsCd)) {
			qc.setOdrStsCd(odrStsCd);
		}
		
		if (StringUtils.isNotEmpty(firstUsrNm)) {
			qc.setFirstUsrNm(firstUsrNm);
		}
		if (StringUtils.isNotEmpty(secondUsrNm)) {
			qc.setSecondUsrNm(secondUsrNm);
		}
		if (StringUtils.isNotEmpty(buOrgCd)) {
			qc.setBuOrgCd(buOrgCd);
		}
        //数据权限
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
        qc.setDataUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
		page.setCondition(qc);
		Pager pager =this.odrBscInfoService.searchListPage(page);
		List<OdrBscInfoVO> list = (List<OdrBscInfoVO>) pager.getResultList();
		ListPageVO<OdrBscInfoVO> listPage = new ListPageVO<OdrBscInfoVO>(list, pager.getTotalCount());
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}	

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			OdrBscInfoVO vo = this.odrBscInfoService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}
	
	/**
	 * 查看附件
	 */
	@RequestMapping(value = "/viewAttachments.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object viewAttachments(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String orgCd = request.getParameter("orgCd");
		String typeCd = request.getParameter("typeCd");

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES);

		SysUlFilesRecQueryCondition condition = new SysUlFilesRecQueryCondition();
		condition.setPkId(id);
		condition.setIsDel(0);
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		condition.setCfgCd(OdrPrdBscInfoConstant.UPLOAD_FILE_ORG_CD);
		condition.setOrgCd(orgCd);

		List<SysUlFilesRecVO> searchList = null;
		JSONArray jsonArray = null;
		try {
			searchList = this.odrBscInfoService.searchSysUlFilesRecList(condition);
			BaseLogUtils.info(logger, "viewAttachments", "查询附件 , 主键ID[pkId : " + id + "]");

			if (CollectionUtils.isNotEmpty(searchList)) {
				jsonArray = new JSONArray();
				for (SysUlFilesRecVO sysUlFilesRecVO : searchList) {
					if(sysUlFilesRecVO.getCfgDtlCd().equals(typeCd)){						
						jsonArray.add(sysUlFilesRecVO.getFilePath());
					}
				}
			}

		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("查询失败");
			BaseLogUtils.info(logger, "viewAttachments", "查询附件失败", e);
		}
		result.setData(jsonArray);

		return result;
	}
	
	/**
	 * 启动流程 yaoxr
	 */
	@RequestMapping(value = "/addFlowStart.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addFlowStart(HttpServletRequest request, HttpServletResponse response) {
		String odrId = request.getParameter("odrId");//预约ID
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(odrId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "addFlowStart", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			
			OdrBscInfoDTO odrBscInfoDTO = this.odrBscInfoApiService.selectById(Long.valueOf(odrId));
			BaseLogUtils.info(logger, "addFlowStart", "=addFlowStart odrBscInfoDTO : "+ JSON.toJSONString(odrBscInfoDTO));
			//查询车抵贷流程最新版本
			SysFlowManageVQueryCondition flowManaQC = new SysFlowManageVQueryCondition();
			flowManaQC.setSysCd(OdrBscInfoConstant.SYS_CD);
			flowManaQC.setIsDel(BaseConstant.IS_YESNO_NO);
			flowManaQC.setIsValid(BaseConstant.IS_YESNO_YES);
			flowManaQC.setModelTyp(FlowConstant.FLOW_MODEL_TYP_PRJ_1);
			flowManaQC.setOrgCd(odrBscInfoDTO.getCstMgrOrgCd());
			flowManaQC.setProcDefKey(OdrBscInfoConstant.ODR_FLOW_DEF_KEY);
			List<SysFlowManageVDTO> flowManageVListForStart = this.flowApiService.searchFlowManageVListForStart(flowManaQC);
			if(CollectionUtils.isEmpty(flowManageVListForStart)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("未查询到可用的流程版本.");
				BaseLogUtils.info(logger, "addFlowStart", "=flowManaQC : "+JSON.toJSONString(flowManaQC)+"=flowManageVListForStart : "+JSON.toJSONString(flowManageVListForStart), CurrentThreadContext.getCurrentUserName());
				return result;
			}
			SysFlowManageVDTO sysFlowManageVDTO = flowManageVListForStart.get(0);
			
			//发起流程
			FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);
			flowStartParamsDTO.setProcDefKey(OdrBscInfoConstant.ODR_FLOW_DEF_KEY);
			flowStartParamsDTO.setProcDefId(sysFlowManageVDTO.getProcDefId());
			flowStartParamsDTO.setProcNo(sysFlowManageVDTO.getProcNo());
			flowStartParamsDTO.setCrtUsrId(odrBscInfoDTO.getCstMgrId());
			flowStartParamsDTO.setBusinessKey(String.valueOf(odrBscInfoDTO.getId()));
			flowStartParamsDTO.setOrgCd(odrBscInfoDTO.getCstMgrOrgCd());
			flowStartParamsDTO.setSysCd(OdrBscInfoConstant.SYS_CD);
			flowStartParamsDTO.setBuOrgCd(odrBscInfoDTO.getBuOrgCd());
			flowStartParamsDTO.setInitiator(String.valueOf(odrBscInfoDTO.getCstMgrId()));
			flowStartParamsDTO.setInitiatorNm(odrBscInfoDTO.getCstMgrNm());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);
			flowStartParamsDTO.setBusinessType(FlowConstant.FLOW_BUSINESS_TYP_PRJ_BSC_INFO);
			flowStartParamsDTO.setModelTyp(FlowConstant.FLOW_MODEL_TYP_PRJ_1);
			
			StringBuffer keyWords = new StringBuffer();
			keyWords.append(odrBscInfoDTO.getOdrNo()+FlowConstant.FLOW_TASK_BACK_USR_DISPLAY_SEPERATOR);//预约编号
			keyWords.append(odrBscInfoDTO.getBuOrgCd()+FlowConstant.FLOW_TASK_BACK_USR_DISPLAY_SEPERATOR);//所属事业部
			keyWords.append(odrBscInfoDTO.getCstNm());//客户名称
			//设置关键字
			flowStartParamsDTO.setSearchDesc(keyWords.toString());
			//客户ID 客户名称
			flowStartParamsDTO.setCstId(String.valueOf(odrBscInfoDTO.getCstId()));
			flowStartParamsDTO.setCstNm(odrBscInfoDTO.getCstNm());
			
			BaseLogUtils.info(logger, "addFlowStart", "=flowStartParamsDTO : "+JSON.toJSONString(flowStartParamsDTO));
			DataResultDTO dataResultDTO = this.flowApiService.noTransFlowStart(flowStartParamsDTO);
			BaseLogUtils.info(logger, "addFlowStart", "=dataResultDTO : "+JSON.toJSONString(dataResultDTO));
			if(!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){//流程发起失败
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}else if(null!=dataResultDTO && null!=dataResultDTO.getData()){
				FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				//result.setData(flowStartedDTO.getMqKey());
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			logger.info(e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员！");
			logger.error("系统错误,请联系管理员！"+e.getMessage());
		}
		return result;
	}
	
	/**
	 * 信审审核预约 附加信息页面
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/toAuditOdrInfoPage.do", method = { RequestMethod.GET})
	public ModelAndView toAuditOdrInfoPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toAuditOdrInfoPage", "跳转信审审核预约 附加信息页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String odrId = request.getParameter("odrId");
		String proIntId = request.getParameter("processInstanceId");//流程实例ID
		String taskId = request.getParameter("taskId");//任务ID
		String taskDefKey = request.getParameter("taskDefKey");//任务KEY
		String isDetail = request.getParameter("isDetail");//1:其他节点 0:信审节点
		String taskNm = request.getParameter("taskNm");//任务名称
		String ctrlKey = request.getParameter("ctrlKey");//资料标识//控制键 1.可上传、下载、删除 2.可验证 3.不可操作
		ModelAndView view = new ModelAndView("carloan/odrbscinfo/odrBscInfoFlow");
		view.addObject("projectId", odrId);
		view.addObject("proIntId", proIntId);
		view.addObject("taskId", taskId);
		view.addObject("taskDefKey", taskDefKey);
		view.addObject("isDetail", isDetail);
		view.addObject("taskNm", taskNm);
		view.addObject("ctrlKey", ctrlKey);
		OdrBscInfoVO vo = new OdrBscInfoVO();
		try {
			vo = this.odrBscInfoService.selectById(Long.valueOf(odrId));
			OdrPrdBscInfoVO odrPrdBscInfoVO = vo.getOdrPrdBscInfoVO();
			ArrayList<Integer> lsPdArr = new ArrayList<Integer>();
			if(null!=odrPrdBscInfoVO){
				Date licDt = odrPrdBscInfoVO.getLicDt();
				Integer monthSpace = CalendarUtils.getMonthSpace(DateUtils.formatDateToString(licDt, DateUtils.YYYY_MM_DD), CalendarUtils.getDateStr(new Date()));
				//查询可选期限
				DataResultDTO result = this.odrPrdBscInfoApiService.getInstalmentPlanAvailablePeriod(monthSpace, odrPrdBscInfoVO.getVehId());
				JSONObject data = (JSONObject) result.getData();
				lsPdArr = (ArrayList<Integer>) data.get("list");
				
			}
			view.addObject("lsPdArr", lsPdArr);
			
			BaseLogUtils.info(logger, "toAuditOdrInfoPage", "[odrPrdBscInfoVO:"+JSON.toJSONString(odrPrdBscInfoVO)+",lsPdArr"+lsPdArr+"]", CurrentThreadContext.getCurrentUserName());
			
			//收入方式
			List<KeyValueVO> profitCdList = this.audReturnVisitService.searchProfitCdList(CurrentThreadContext.getCurrentSysCd(), "00000001");
			view.addObject("profitCdList", profitCdList);
			//主货物大类
			List<KeyValueVO> mainGdsTypCdList = this.audCreditInfoService.searchGoodsTypListByLvl("1");
			view.addObject("mainGdsTypCdList", mainGdsTypCdList);
			//货物来源
			List<KeyValueVO> goodsResList = this.audReturnVisitService.searchGoodsResList();
			view.addObject("goodsResList", goodsResList);
			//主货物结算方式
			List<KeyValueVO> gdsStlWayCdList = this.audReturnVisitService.searchGdsStlWayCdList();
			view.addObject("gdsStlWayCdList", gdsStlWayCdList);
			//司机情况
			List<KeyValueVO> driverList = this.audReturnVisitService.searchDriverList();
			view.addObject("driverList", driverList);
			//第二还款来源
			List<KeyValueVO> secondPayResCdList = this.audReturnVisitService.searchSecondPayResCdList();
			view.addObject("secondPayResCdList", secondPayResCdList);
			
			//是否
			List<KeyValueVO> yesOrNoCdList = this.audStandingBookService.searchYesOrNoCdList();
			view.addObject("yesOrNoCdList", yesOrNoCdList);
			//流程审核意见
			List<KeyValueVO> processOpinionCdList = this.audStandingBookService.searchProcessOpinionCdList();
			view.addObject("processOpinionCdList", processOpinionCdList);
			//客户经理评级
			List<KeyValueVO> cstMgrLvlCdList = this.audInterviewInfoService.searchCstMgrLvlCdList();
			view.addObject("cstMgrLvlCdList", cstMgrLvlCdList);
			//首付款来源
			List<KeyValueVO> firstPayResCdList = this.audInterviewInfoService.searchFirstPayResCdList();
			view.addObject("firstPayResCdList", firstPayResCdList);
			//风控评级
			List<KeyValueVO> riskCtrlLvlCdList = this.audInterviewInfoService.searchRiskCtrlLvlCdList();
			view.addObject("riskCtrlLvlCdList", riskCtrlLvlCdList);
			//运营年限/本地生活年限
			List<KeyValueVO> bizExpList = this.audReturnVisitService.searchBizExpList();
			view.addObject("bizExpList", bizExpList);
			
			List<KeyValueVO> equCategoryCdList = this.prjBscInfoService.searchEquCategoryCdList(CurrentThreadContext.getCurrentSysCd(), vo.getBuOrgCd());
			view.addObject("equCategoryCdListJSON", JSON.toJSONString(equCategoryCdList));
			
			//查询数据字典配置
			Double lgjAmt = null;//留购价
			Double yearPct = null;//年利率
			List<String> grpCdList = new ArrayList<String>();
			grpCdList.add(DictionaryConstant.CODE__CDD_FEE_LIST);
			grpCdList.add(DictionaryConstant.CODE__PRJ_ODR_DEF_ANN);
			Map<String, List<KeyValueVO>> multiKvList = this.sysDictionaryApiService.getMultiKvList(grpCdList, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			if(!multiKvList.isEmpty()){
				List<KeyValueVO> lgjAmtList = multiKvList.get(DictionaryConstant.CODE__CDD_FEE_LIST);
				if(CollectionUtils.isNotEmpty(lgjAmtList)){
					KeyValueVO keyValueVO = lgjAmtList.get(0);
					if(StringUtils.isNotEmpty(keyValueVO.getValue())){
						lgjAmt = DecimalUtils.convertFenToYuan(Long.valueOf(keyValueVO.getValue()));
					}
				}
				List<KeyValueVO> yearPctList = multiKvList.get(DictionaryConstant.CODE__PRJ_ODR_DEF_ANN);
				if(CollectionUtils.isNotEmpty(yearPctList)){
					KeyValueVO keyValueVO = yearPctList.get(0);
					if(StringUtils.isNotEmpty(keyValueVO.getValue())){
						yearPct = Double.valueOf(keyValueVO.getValue());
					}
				}
			}
			view.addObject("lgjAmt", lgjAmt);
			view.addObject("yearPct", yearPct);
		} catch (Exception e) {
			BaseLogUtils.info(logger, "toAuditOdrInfoPage", "=跳转信审审核预约 附加信息页面查询数据异常=odrId:"+odrId, e);
			e.printStackTrace();
		}
		view.addObject("odrBscInfo",vo);
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toAuditOdrInfoPage", " 跳转信审审核预约 附加信息页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 获取风控策略结果
	 * @param request
	 * @param response
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/getRiskControlResults.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getRiskControlResults(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getRiskControlResults", "获取风控策略结果.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String cstId = request.getParameter("cstId");
		String lnkCompId = request.getParameter("lnkCompId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		try {
			String riskControlResults = this.prjPrdPaySchMService.riskControlResults(StringUtils.isNotEmpty(cstId)?Long.valueOf(cstId):null, 
					StringUtils.isNotEmpty(lnkCompId)?Long.valueOf(lnkCompId):null);
			result.setData(riskControlResults);
			BaseLogUtils.info(logger, "getRiskControlResults", "获取风控策略结果", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getRiskControlResults", "获取风控策略结果失败.", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getRiskControlResults", "获取风控策略结果异常.", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getRiskControlResults", "获取风控策略结果.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}
}

